<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Form for adding events
 *
 * @category    RedCross
 * @package     Admin_Form_Event
 */
class Admin_Form_Event_Add extends RedCross_Form
{

	public function init()
	{
		$this->addPrefixPath('RedCross_Form_Element', 'RedCross/Form/Element', 'element');

		$this->setAttrib('id', 'event_add');
		
        $this->addElement('select', 'type', array(
            'required' => true,
            'label' => "Type",
            'multiOptions' => array(
                'Vaktarrangement' => 'Vaktarrangement',
                'Sosialt' => 'Sosialt',
                'Kurs' => 'Kurs',
                'Møte' => 'Møte',
                'Øvelse' => 'Øvelse',
                'Frist' => 'Frist',
                'Beredskap' => 'Beredskap',
                'Annet' => 'Annet',
            ),
            'value' => 'Vaktarrangement'
        ));

		$this->addElement('text', 'name', array(
			'filters' 		=> array('StringTrim'),
			'validators'	=> array(
                array('StringLength', true, array(2, 64)),
            ),
            'required'	=> true,
            'label'		=> 'Navn:',
		));

		$this->addElement('textarea', 'description', array(
			'filters'		=> array('StringTrim'),
            'rows'		=> '5',
            'cols'		=> '60',
            'required'	=> false,
            'label'		=> 'Beskrivelse:',
		));

		$this->addElement('text', 'location', array(
			'filters'		=> array('StringTrim'),
			'validators'	=> array(
				array('StringLength', true, array(2, 255)),
            ),
            'required'	=> false,
            'label'		=> 'Sted:',
		));

        $this->addElement('text', 'redcross_contact', array(
            'filters'   => array('StringTrim'),
            'validators'    => array(
                array('StringLength', true, array(2, 64)),
            ),
            'required'  => true,
            'label'     => 'Røde Kors-kontakt',
        ));

		$this->addElement('text', 'contact_name', array(
			'filters'		=> array('StringTrim'),
			'validators'	=> array(
				array('StringLength', true, array(2, 64)),
            ),
            'required'	=> false,
            'label'		=> 'Arrangørkontakt:',
		));

		$this->addElement('text', 'contact_phone', array(
			'filters'		=> array('StringTrim'),
			'validators'	=> array(
                array('Digits'),
				array('StringLength', true, array(8, 8)),
            ),
            'required'	=> false,
            'label'		=> 'Tlf. kontaktperson:',
		));

		$this->addElement('text', 'from_date', array(
		'filters'		=> array('StringTrim'),
		'validators'	=> array(
			array('Date', true, array('locale' => 'nb_NO')),
//			array('ValidDate', true, array('type' => 'from_date')),
		),
			'required' 		=> true,
			'label'			=> 'Start Dato:'
		));

		$this->addElement('time', 'from_time', array(
			'required'	=> true,
			'validators'	=> array(
				array('Time',true,array('name' => 'from_time')),
			),
			'label'		=> 'Starttidspunkt:'
		));

		$this->addElement('text', 'to_date', array(
            'filters'		=> array('StringTrim'),
            'validators'	=> array(
                array('Date', true, array('locale' => 'nb_NO')),
//                array('ValidDate', true, array('type' => 'to_date')),
            ),
			'required'		=> true,
			'label'			=> 'Slutt Dato:'
		));

		$this->addElement('time', 'to_time', array(
			'required'	=> true,
			'validators'	=> array(
				array('Time',true,array('name' => 'to_time')),
			),
			'label'		=> 'Sluttidspunkt:'
		));

		$this->addElement('textarea', 'requested_resource', array(
			'filters'		=> array('StringTrim'),
            'rows'		=> '5',
            'cols'		=> '60',
            'required' 	=> false,
            'label'		=> 'Ressurser:'
		));

		$this->addElement('submit', 'submit', array(
            'required' => true,
            'ignore'   => true,
            'label'    => 'Lagre',
        ));
        $this->fillFormValues();
	}
    private function fillFormValues() {
        $_authService = RedCross_Factory::getService('Core_Service_Auth');
        $_memberService = RedCross_Factory::getService('Core_Service_Member');

        $user = $_authService->getIdentity();
        $member = $_memberService->fetchByUsername($user->username);
        $redcrossContact = $member->first_name . ' ' . $member->last_name;

        $templateElement = $this->getElement('redcross_contact');
        $templateElement->setValue($redcrossContact);
    }

}
